﻿using NaireSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NaireSystem;
using System.Collections.ObjectModel;
using TYBase;
using NaireSystem.Views.UserManager;
using NaireSystem.Api.VO;

namespace NaireSystem.Datas
{
    public class UIDataHelper
    {
        public static QtModel DataAsUI(QtVO data)
        {
            QtModel quetionModel = new QtModel(data)
            {
                Score = data.score,
                Title = data.title,
                Tag = data.tag,
                CreatorName = data.createName,
                StrCreateTime = data.createTime.AsString(),
                ListOption = new ObservableCollection<OptionModel>(),

            };
            for (int i = 0; i < data.listOption.Count; i++)
            {
                OptionModel optionItem = new OptionModel()
                {
                    Name = data.listOption[i],
                    IndexChar = (quetionModel.ListOption.Count).NumberToABC()
                };
                if (data.listAnswer != null && data.listAnswer.Contains(i))
                {
                    optionItem.IsSelected = true;
                }
                quetionModel.ListOption.Add(optionItem);
            }
            return quetionModel;
        }

        internal static NaireRecordModel DataAsUI(ExamVO x)
        {
            NaireRecordModel model = new NaireRecordModel(x);
            model.Title = x.title;
            model.OfficeCount = x.deptCount;
            model.Count = x.finishCount;
            //model.OfficeCount=x.cou
            model.CreateTime = x.createTime.AsString();
            return model;
            //model.CreateTime = x.createTime.AsString();
        }

        public static UserInfoModel DataAsUI(UserInfoVo userInfo)
        {
            return new UserInfoModel(userInfo)
            {
                UserAge = userInfo.user_age,
                UserId = userInfo.user_id,
                UserLevel = AppDictData.GetLabel(Enums.EnumDictType.user_level, userInfo.user_level_key),
                WorkYear = userInfo.user_work_year,
                UserName = userInfo.user_name,
                userEducation = AppDictData.GetLabel(Enums.EnumDictType.user_education, userInfo.user_education_key),
                UserMajor = AppDictData.GetLabel(Enums.EnumDictType.user_major, userInfo.user_major_key),
                UserTitle = AppDictData.GetLabel(Enums.EnumDictType.user_title, userInfo.user_title_key),
                UserStartWorkTime = userInfo.user_start_work_date?.ToString("yyyy-MM-dd"),
                DeptName = userInfo.dept_name,
            };
        }



        static IntStringData DataAsShiftModel(ObservableCollection<IntStringData> listShift, int key)
        {

            IntStringData data = listShift.FirstOrDefault(x => x.Key == key);
            if (data == null)
            {
                data = new IntStringData { Key = key, Value = AppDictData.GetLabel(Enums.EnumDictType.shift, key) };
            }
            return data;

        }

        internal static ScheduleModel DataAsUI(ScheduleVO item, ObservableCollection<IntStringData> listShift)
        {
            ScheduleModel model = new ScheduleModel(item)
            {
                UserName = item.user_name,

            };
            model.Shift1_key = DataAsShiftModel(listShift, item.shift1_key);
            model.Shift2_key = DataAsShiftModel(listShift, item.shift2_key);
            model.Shift3_key = DataAsShiftModel(listShift, item.shift3_key);
            model.Shift4_key = DataAsShiftModel(listShift, item.shift4_key);
            model.Shift5_key = DataAsShiftModel(listShift, item.shift5_key);
            model.Shift6_key = DataAsShiftModel(listShift, item.shift6_key);
            model.Shift7_key = DataAsShiftModel(listShift, item.shift7_key);

            return model;
        }

        internal static LearnFileModel DataAsUI(LearnFileVO x)
        {
            return new LearnFileModel(x)
            {
                CreateTime = x.create_time.AsString(),
                CreatorName = x.creator_name,
                FileName = x.file_name,
                FileSize = x.file_size,
                FileType = x.file_type,
                FileTag = x.file_tag,
                Title = x.title,
            };
        }
    }
}
